package com.softeem.test;

import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.softeem.domain.Admin;
import com.softeem.domain.Comment;
import com.softeem.domain.ShoppingCar;
import com.softeem.domain.Travle;
import com.softeem.domain.vo.CommentVO;
import com.softeem.mapper.AdminMapper;
import com.softeem.service.ICommentService;
import com.softeem.utils.RandomCodeUtils;
import io.swagger.models.auth.In;
import oracle.jrockit.jfr.ActiveRecordingEvent;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.ui.Model;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;

@SpringBootTest
@RunWith(SpringJUnit4ClassRunner.class)
public class test {
    @Autowired
    private AdminMapper mapper;
    @Autowired
    ICommentService service;
    @Autowired
    StringRedisTemplate redisTemplate;


    @Test
    public void method(){

        Travle travle = new Travle();
        List<Travle> travles = travle.selectAll();
        //model.addAttribute("traList",travles);

        System.out.println(travles);

    }

    @Test
    public void method2(){
        List<CommentVO> allComment = service.findAllComment();
        System.out.println(allComment);
    }

    @Test
    public void method3(){

        RandomCodeUtils randomCodeUtils = new RandomCodeUtils();
        Integer codes = randomCodeUtils.getRandomCodes(4);
        String s = String.valueOf(codes);
        System.out.println(s);
        redisTemplate.opsForValue().set("codes",s,12, TimeUnit.SECONDS);
    }

    //测试取redis数据
    @Test
    public void method4(){

        int size = redisTemplate.opsForHash().keys("1001").size();
        System.out.println(size);

//        Object s = redisTemplate.opsForHash().get("1001","1");
//        System.out.println(s);
        System.out.println("----------------------------------------");
        for (int i = 1;i<redisTemplate.opsForHash().keys("1001").size()+1;i++){
            Object s1 = redisTemplate.opsForHash().get("1001",String.valueOf(i));
            System.out.println(s1);}




    }

    @Test
    public void method5() throws JsonProcessingException {
       String str = "{'name':'tom',‘age’：22}";

        ObjectMapper objectMapper = new ObjectMapper();
        ShoppingCar shoppingCar = objectMapper.readValue(str, ShoppingCar.class);
    }


}

